package springmvc_demo.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @GetMapping("/login")
    public String login(){
        return "login";
    }
    @PostMapping("/login")
    public String loginIn(String username, String password, HttpSession httpSession){ //HttpSession 保存用户信息
        if(username.equals("admin") && password.equals("123")){
            httpSession.setAttribute("username","admin");
            return "redirect:index";

        }else
            return  "login";

    }
}
